#include "ExcelOper.h"

ExcelOper::ExcelOper(QObject *parent) : QObject(parent)
{

}

void ExcelOper::delSpecialCol()
{
    QXlsx::Document xlsxW("measurement_result_2D_284.xlsx");

    QXlsx::Document xlsxWDst("dst.xlsx");

    if(xlsxW.load()) {
        QStringList sheetList = xlsxW.sheetNames();
        QVector<int> needToDeleteColList;

        int rowCount = 1;
        int colCount = xlsxW.dimension().columnCount();
        for(int i = 1; i <= rowCount; ++i) {
            for(int j = 1; j <= colCount; ++j) {
                Cell *cell = xlsxW.cellAt(i, j);

                if(nullptr != cell) {
                    QVariant var = cell->readValue();
                    QString cellStr = var.toString();
                    if(!cellStr.contains("-distance")) {
                        needToDeleteColList.push_back(j);
                    }
                }
            }
        }

        rowCount = xlsxW.dimension().rowCount();

        for(int i = 1; i <= rowCount; ++i) {
            int traverCol = 1;
            for(int j = 1; j <= colCount; j++) {
                if(!needToDeleteColList.contains(j)) {
                    Cell *cell = xlsxW.cellAt(i, j);
                    if(nullptr != cell) {
                        QVariant val = cell->value();
                        xlsxWDst.write(i, traverCol, val);
                        traverCol++;
                    }
                }
            }
        }
    }
    xlsxWDst.save();
}
